<!-- Dashboard.vue -->
<template>
  <div ref="chartContainer" style="width: 100%; height: 500px"></div>
</template>

<script setup>
import { ref, onMounted } from "vue";
import * as echarts from "echarts";

const chartContainer = ref(null);

onMounted(() => {
  // 初始化 ECharts 实例
  const chartInstance = echarts.init(chartContainer.value);

  // 配置 ECharts 图表
  const options = {
    title: {
      text: "ECharts 示例",
    },
    tooltip: {},
    legend: {
      data: ["销量"],
    },
    xAxis: {
      data: ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"],
    },
    yAxis: {},
    series: [
      {
        name: "销量",
        type: "bar",
        data: [5, 20, 36, 10, 10, 20],
      },
    ],
  };

  // 设置图表的配置项
  chartInstance.setOption(options);

  // 监听窗口大小变化
  window.addEventListener("resize", () => {
    chartInstance.resize();
  });

  // 清理事件监听器（如果页面被销毁）
  onBeforeUnmount(() => {
    window.removeEventListener("resize", () => {
      chartInstance.resize();
    });
    chartInstance.dispose();
  });
});
</script>

<style scoped>
/* Optional: You can add custom styles here */
</style>
